//第2关 上转型对象的使用，多态的特性


package step2;

abstract class Employee {
	public abstract double earnings();
}
class YearWorker extends Employee {
	//重写earnings()方法
    /********** Begin **********/
	public double earnings() {
		return 100000;
	}

	/********** End **********/	                                               		
}
class MonthWorker extends Employee {
	//重写earnings()方法
    /********** Begin **********/
	public double earnings() {
		return 10000*12;
	}

	/********** End **********/	                                               		
}
class WeekWorker extends Employee {
	//重写earnings()方法
    /********** Begin **********/
	public double earnings() {
		return 5000*4*12;
	}

	/********** End **********/	                                                		
}
class Company {
	Employee[] employees;
	double salaries = 0;
	Company(Employee[] employees) {
		this.employees = employees;
	}
	public double salariesPay() {
		salaries = 0;
		//计算salaries
		/********** Begin **********/
		for(Employee s:employees) {
			salaries += s.earnings();
		}

	    /********** End **********/	                             		
		return salaries;
	}	
}
public class HardWork {
	public static void main(String[] args) {
		Employee[] employees = new Employee[20];
		for (int i = 0; i < employees.length; i++) {
			if(i%3==0)
				employees[i] = new WeekWorker();
			else if(i%3==1)
				employees[i] = new MonthWorker();
			else if(i%3==2)package step3;

// 自行设计接口和实现类
/********** Begin **********/
			interface Display {
				void display();
			}

			class Inform implements Display {
				public void display() {
					System.out.println("通知内容");
				}
			}

			class Car implements Display {
				public void display() {
					System.out.println("汽车油量");
				}
			}

			class Adervise implements Display {
				public void display() {
					System.out.println("广告消息");
				}
			}
/********** End **********/

			public class Lab3_3 {
				public static void main(String[] args) {
					Display[] arr = { new Inform(), new Car(), new Adervise() };
					for (Display d : arr) {
						d.display();
					}
				}
			}

			employees[i] = new YearWorker();
		}
		Company company = new Company(employees);
		System.out.println("公司年工资总额:" + company.salariesPay());
	}
}
